package com.zmx.doctor.view.activity;

import android.annotation.SuppressLint;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.text.Editable;
import android.text.Html;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AlertDialog;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.google.gson.Gson;
import com.wang.adapters.interfaceabstract.OnItemClickListener;
import com.zmx.doctor.BaseActivity;
import com.zmx.doctor.R;
import com.zmx.doctor.adapter.GoodsItemAdapter;
import com.zmx.doctor.adapter.NewPrescribingAdapter;
import com.zmx.doctor.listener.InformUpdateListenerManager;
import com.zmx.doctor.okhttp.OkHttp3ClientManager;
import com.zmx.doctor.pojo.Goods;
import com.zmx.doctor.pojo.GoodsOrder;
import com.zmx.doctor.utils.AllUtil;
import com.zmx.doctor.view.util.MySharedPreferences;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class NewPrescribingActivity extends BaseActivity {

    @BindView(R.id.layout_data)
    LinearLayout layout_data;
    @BindView(R.id.search)
    EditText search;
    @BindView(R.id.rv_view)
    RecyclerView rvView;
    @BindView(R.id.search_view)
    RecyclerView search_view;
    @BindView(R.id.button)
    Button button;
    @BindView(R.id.text_number)
    TextView textNumber;
    @BindView(R.id.z_goods)
    TextView z_goods;

    private NewPrescribingAdapter adapter;
    private List<GoodsOrder> lists;

    private GoodsItemAdapter goodsItemAdapter;
    private List<Goods> goods;

    private Integer logo;
    private String ask_id, p_id, z_type, temp_id;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_new_prescribing;
    }

    @Override
    protected void initViews() {

        ButterKnife.bind(this);
        setToolbar(R.id.tool_bar);


        logo = Integer.parseInt(getIntent().getStringExtra("logo"));
        z_type = this.getIntent().getStringExtra("z_type");
        temp_id = this.getIntent().getStringExtra("temp_id");

        if (logo == 1) {

            button.setText("发 送 处 方");
            ask_id = getIntent().getStringExtra("ask_id");
            p_id = getIntent().getStringExtra("p_id");


        } else {

            button.setText("保 存 处 方");

        }

        goods = new ArrayList<>();
        goodsItemAdapter = new GoodsItemAdapter(mActivity);
        search_view.setLayoutManager(new LinearLayoutManager(this));
        search_view.setAdapter(goodsItemAdapter);
        search.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void afterTextChanged(Editable editable) {


                if (!search.getText().toString().equals("")){

                    searchUsre();

                }else{

                    goods.clear();
                    goodsItemAdapter.notifyDataSetChanged();
                    layout_data.setVisibility(View.VISIBLE);

                }


            }

        });
        goodsItemAdapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            protected void onItemClick(View view, int listPosition) {

                showPhoto(goods.get(listPosition));

            }
        });



        adapter = new NewPrescribingAdapter(mActivity);
        rvView.setLayoutManager(new LinearLayoutManager(mActivity));
        rvView.setAdapter(adapter);
        lists = new ArrayList<>();
        adapter.setListAndNotifyDataSetChanged(lists);
        adapter.setOnItemClickListener(new OnItemClickListener() {
            @Override
            protected void onItemClick(View view, int listPosition) {


                new AlertDialog.Builder(mActivity)
                        .setTitle("提示")
                        .setMessage("选择操作")
                        .setPositiveButton("删除", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {

                                new AlertDialog.Builder(mActivity)
                                        .setTitle("提示")
                                        .setMessage("确定删除该药品？")
                                        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialogInterface, int i) {

                                                lists.remove(lists.get(listPosition));
                                                adapter.notifyItemRemoved(listPosition);
                                                adapter.notifyItemRangeRemoved(listPosition, lists.size());

                                            }
                                        })
                                        .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                                            @Override
                                            public void onClick(DialogInterface dialogInterface, int i) {

                                            }
                                        }).show();


                            }
                        })
                        .setNegativeButton("修改", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {

                                showPhoto(lists.get(listPosition), listPosition);

                            }
                        }).show();


            }
        });


    }

    @SuppressLint("HandlerLeak")
    private Handler handler = new Handler() {

        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);

            switch (msg.what) {

                case 0:

                    textNumber.setText("已选择" + lists.size() + "种药品");
                    adapter.notifyDataSetChanged();

                    break;
                case 1:

                    try {

                        JSONObject object = new JSONObject(msg.obj.toString());
                        Toast(object.getString("msg"));
                        if (object.getInt("code") == 1) {
                            finish();
                        }

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }

                    break;

                case 2:


                    try {

                        JSONObject object = new JSONObject(msg.obj.toString());
                        Toast(object.getString("msg"));
                        if (object.getInt("code") == 1) {

                            JSONObject data = object.getJSONObject("data");

                            InformUpdateListenerManager informUpdateListenerManager = new InformUpdateListenerManager(mActivity);
                            informUpdateListenerManager.getInstance(mActivity).updateChat(data.getString("content"));
                            finish();
                        }

                    } catch (JSONException e) {
                        e.printStackTrace();
                    }


                    break;

                case 3:

                    goods.clear();
                    try {

                        JSONObject object = new JSONObject(msg.obj.toString());

                        if (object.getInt("code") == 1){

                            JSONArray array = object.getJSONArray("data");
                            Gson gson = new Gson();
                            for (int i = 0; i < array.length(); i++) {

                                Goods g = gson.fromJson(array.getJSONObject(i).toString(), Goods.class);
                                goods.add(g);

                            }

                            layout_data.setVisibility(View.GONE);
                            goodsItemAdapter.setListAndNotifyDataSetChanged(goods);//就是设置list然后刷新

                        }else {

                            Toast("没有该药品，请自建药品");

                            layout_data.setVisibility(View.VISIBLE);
                        }


                    } catch (JSONException e) {
                        e.printStackTrace();
                    }


                    break;

            }

        }
    };


    private Dialog modify_dialogs;//弹出框

    public void showPhoto() {

        View view;//选择性别的view

        modify_dialogs = new Dialog(mActivity, R.style.ActionSheetDialogStyle);
        //填充对话框的布局
        view = LayoutInflater.from(mActivity).inflate(R.layout.dialog_goods, null);
        //将布局设置给Dialog
        modify_dialogs.setContentView(view);
        //获取当前Activity所在的窗体
        Window dialogWindow = modify_dialogs.getWindow();

        //设置Dialog从窗体底部弹出
        dialogWindow.setGravity(Gravity.BOTTOM);
        //获得窗体的属性
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        //        lp.y = 20;//设置Dialog距离底部的距离

        //// 以下这两句是为了保证按钮可以水平满屏
        lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
        lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        // 设置显示位置
        modify_dialogs.onWindowAttributesChanged(lp);
        //       将属性设置给窗体
//        modify_dialogs.setCanceledOnTouchOutside(false);
        modify_dialogs.show();//显示对话框

        EditText e_name = view.findViewById(R.id.e_name);
        EditText e_specs = view.findViewById(R.id.e_specs);
        EditText e_every = view.findViewById(R.id.e_every);
        EditText e_day = view.findViewById(R.id.e_day);
        EditText e_describe = view.findViewById(R.id.e_describe);
        TextView regular = view.findViewById(R.id.regular);
        regular.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                final String[] items = {"片/次", "瓶/次", "剂/次"};
                showNotice(regular, items);
            }
        });
        TextView e_rate = view.findViewById(R.id.e_rate);
        e_rate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                final String[] items = {"每日一次", "每日二次", "每日三次"};
                showNotice(e_rate, items);
            }
        });
        TextView e_usage = view.findViewById(R.id.e_usage);
        e_usage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                final String[] items = {"口服", "外用", "注射"};
                showNotice(e_usage, items);
            }
        });

        Button submit = view.findViewById(R.id.submit);
        submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                if (e_name.getText().toString().equals("")) {

                    Toast("名称不能为空！");
                    return;

                }

                if (e_specs.getText().toString().equals("")) {

                    Toast("规格不能为空！");
                    return;

                }
                if (e_every.getText().toString().equals("")) {

                    Toast("用量不能为空！");
                    return;

                }
                if (e_day.getText().toString().equals("")) {

                    Toast("用药时长不能为空！");
                    return;

                }

                GoodsOrder go = new GoodsOrder();
                go.setGoods_id(0);
                go.setGoods_name(e_name.getText().toString());
                go.setPrice(0);
                go.setNumber(Integer.parseInt(e_every.getText().toString()));
                go.setSpecs(e_specs.getText().toString());
                go.setDay(e_day.getText().toString());
                go.setDescribes(e_describe.getText().toString());
                go.setRate(e_rate.getText().toString());
                go.setUsage(e_usage.getText().toString());
                go.setType(1);
                lists.add(go);
                handler.sendEmptyMessage(0);

                Toast("自建成功");
                modify_dialogs.dismiss();

            }
        });

    }

    public void showPhoto(GoodsOrder go, Integer listPosition) {

        View view;//选择性别的view

        modify_dialogs = new Dialog(mActivity, R.style.ActionSheetDialogStyle);
        //填充对话框的布局
        view = LayoutInflater.from(mActivity).inflate(R.layout.dialog_shopping, null);
        //将布局设置给Dialog
        modify_dialogs.setContentView(view);
        //获取当前Activity所在的窗体
        Window dialogWindow = modify_dialogs.getWindow();

        //设置Dialog从窗体底部弹出
        dialogWindow.setGravity(Gravity.BOTTOM);
        //获得窗体的属性
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        //        lp.y = 20;//设置Dialog距离底部的距离

        //// 以下这两句是为了保证按钮可以水平满屏
        lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
        lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        // 设置显示位置
        modify_dialogs.onWindowAttributesChanged(lp);
        //       将属性设置给窗体
//        modify_dialogs.setCanceledOnTouchOutside(false);
        modify_dialogs.show();//显示对话框

        TextView name = view.findViewById(R.id.name);
        name.setText("商品名称" + go.getGoods_name());
        TextView desc = view.findViewById(R.id.desc);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {

            if (go.getDescribe() != null) {

                desc.setText("药品描述：" + Html.fromHtml((go.getDescribe()), 10));

            } else {
                desc.setVisibility(View.GONE);
            }

        }
        EditText y_number = view.findViewById(R.id.y_number);
        y_number.setText(go.getNumber() + "");
        EditText y_sm = view.findViewById(R.id.y_sm);
        y_sm.setText(go.getDescribes());
        EditText e_day = view.findViewById(R.id.e_day);
        e_day.setText(go.getDay());

        TextView regular = view.findViewById(R.id.regular);
        regular.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                final String[] items = {"片/次", "瓶/次", "剂/次"};
                showNotice(regular, items);
            }
        });
        TextView e_rate = view.findViewById(R.id.e_rate);
        e_rate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                final String[] items = {"每日一次", "每日二次", "每日三次"};
                showNotice(e_rate, items);
            }
        });
        TextView e_usage = view.findViewById(R.id.e_usage);
        e_usage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                final String[] items = {"口服", "外用", "注射"};
                showNotice(e_usage, items);
            }
        });

        Button submit = view.findViewById(R.id.submit);
        submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (y_number.getText().toString().equals("")) {

                    Toast("数量不能为空！");
                    return;

                }

                if (y_sm.getText().toString().equals("")) {

                    Toast("使用说明不能为空！");
                    return;

                }
                if (e_day.getText().toString().equals("")) {

                    Toast("用药时长不能为空！");
                    return;

                }

                go.setNumber(Integer.parseInt(y_number.getText().toString()));
                go.setUsage(y_sm.getText().toString());
                go.setDay(e_day.getText().toString());
                go.setType(1);
                lists.set(listPosition, go);
                adapter.notifyDataSetChanged();
                modify_dialogs.dismiss();

            }
        });

    }

    private AlertDialog alertDialog1; //信息框

    public void showNotice(TextView textView, String[] items) {
        AlertDialog.Builder alertBuilder = new AlertDialog.Builder(mActivity);
        alertBuilder.setTitle("请选择");
        alertBuilder.setItems(items, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialogInterface, int i) {
                textView.setText(items[i]);
                alertDialog1.dismiss();
            }
        });
        alertDialog1 = alertBuilder.create();
        alertDialog1.show();
    }


    @OnClick({R.id.button, R.id.z_goods})
    public void onViewClicked(View view) {
        switch (view.getId()) {

//            case R.id.search_btn:
//                Intent intent = new Intent();
//                intent.setClass(mActivity, SearchDrugActivity.class);
//                startActivityForResult(intent, 101);
//                break;

            case R.id.button:
                alert_label();
                break;

            case R.id.z_goods:

                showPhoto();

                break;
        }
    }

    public void alert_label() {

        AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);

        LayoutInflater factory = LayoutInflater.from(mActivity);//提示框
        final View view = factory.inflate(R.layout.dialog_edit, null);//这里必须是final的
        final EditText et = view.findViewById(R.id.editText);
        et.setHint("输入处方名称");
        builder.setTitle("输入处方名称");

        final AlertDialog dialog = builder.create();
        dialog.setView(view);

        dialog.setButton(DialogInterface.BUTTON_POSITIVE, "提交", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {

            }
        });

        dialog.setButton(DialogInterface.BUTTON_NEUTRAL, "取消", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int which) {
                dialog.dismiss();
            }
        });
        dialog.show();

        dialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {

                if (!TextUtils.isEmpty(et.getText().toString())) {
                    if (logo == 1) {

                        if (Integer.parseInt(z_type) == 1) {

                            sendMake(et.getText().toString());

                        } else {

                            sendMakes(et.getText().toString());

                        }


                    } else {
                        setMakeTemp(et.getText().toString());
                    }

                    dialog.dismiss();

                } else {

                    Toast("非法输入");

                }

            }
        });


    }

//    @Override
//    public void onActivityResult(int requestCode, int resultCode, Intent data) {
//
//        if (data != null) {
//
//            switch (requestCode) {  //根据请求码可处理不同活动返回的数据
//
//                case 101: //返回的请求码
//
//                    Bundle bundle = data.getExtras();
//                    List<GoodsOrder> gos = (List<GoodsOrder>) bundle.getSerializable("goods_car");
//
//                    if (gos != null) {
//
//                        for (GoodsOrder g : gos) {
//
//                            lists.add(g);
//
//                        }
//                        handler.sendEmptyMessage(0);
//
//                    }
//
//                    break;
//            }
//
//        }
//
//
//    }


    public void setMakeTemp(String title) {

        Gson gson = new Gson();
        String taskInfo = gson.toJson(lists);

        List<String> l = new ArrayList<>();
        l.add("");
        l.add(taskInfo + "");
        l.add(title);

        //请求网络
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("sign", AllUtil.md5(sing(l)));
        params.put("token", MySharedPreferences.getInstance(mActivity).getString(MySharedPreferences.token, ""));
        params.put("uid", MySharedPreferences.getInstance(mActivity).getString(MySharedPreferences.uid, ""));
        params.put("ts", System.currentTimeMillis() / 1000); // 当前时间戳
        params.put("cmd", "setMakeTemp");
        params.put("data[make]", taskInfo);
        params.put("data[advice]", "");
        params.put("data[title]", title);
        OkHttp3ClientManager.getInstance().NetworkRequestMode("http://zmx.123xk.cn/admin/api.make/entry", params, handler, 1, 404);

    }

    public void sendMake(String title) {

        Gson gson = new Gson();
        String taskInfo = gson.toJson(lists);

        List<String> l = new ArrayList<>();
        l.add("");
        l.add(ask_id);
        l.add(taskInfo + "");
        l.add(p_id);
        l.add(title);

        //请求网络
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("sign", AllUtil.md5(sing(l)));
        params.put("token", MySharedPreferences.getInstance(mActivity).getString(MySharedPreferences.token, ""));
        params.put("uid", MySharedPreferences.getInstance(mActivity).getString(MySharedPreferences.uid, ""));
        params.put("ts", System.currentTimeMillis() / 1000); // 当前时间戳
        params.put("cmd", "sendMake");
        params.put("data[make]", taskInfo);
        params.put("data[ask_id]", ask_id);
        params.put("data[patient_id]", p_id);
        params.put("data[advice]", "");
        params.put("data[title]", title);
        OkHttp3ClientManager.getInstance().NetworkRequestMode("http://zmx.123xk.cn/admin/api.make/entry", params, handler, 2, 404);

    }

    public void sendMakes(String title) {

        Gson gson = new Gson();
        String taskInfo = gson.toJson(lists);

        List<String> l = new ArrayList<>();
        l.add("");
        l.add(ask_id);
        l.add(taskInfo + "");
        l.add(p_id);
        l.add(temp_id);
        l.add(title);

        //请求网络
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("sign", AllUtil.md5(sing(l)));
        params.put("token", MySharedPreferences.getInstance(mActivity).getString(MySharedPreferences.token, ""));
        params.put("uid", MySharedPreferences.getInstance(mActivity).getString(MySharedPreferences.uid, ""));
        params.put("ts", System.currentTimeMillis() / 1000); // 当前时间戳
        params.put("cmd", "teamSendMake");
        params.put("data[make]", taskInfo);
        params.put("data[ask_id]", ask_id);
        params.put("data[patient_id]", p_id);
        params.put("data[advice]", "");
        params.put("data[team_id]", temp_id);
        params.put("data[title]", title);
        OkHttp3ClientManager.getInstance().NetworkRequestMode("http://zmx.123xk.cn/admin/api.team/entry", params, handler, 2, 404);

    }


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }


    public void searchUsre() {

        List<String> ls = new ArrayList<>();
        ls.add(search.getText().toString());
        //请求网络
        Map<String, Object> params = new HashMap<String, Object>();
        params.put("sign", AllUtil.md5(sing(ls)));
        params.put("token", MySharedPreferences.getInstance(mActivity).getString(MySharedPreferences.token, ""));
        params.put("uid", MySharedPreferences.getInstance(mActivity).getString(MySharedPreferences.uid, ""));
        params.put("ts", System.currentTimeMillis() / 1000); // 当前时间戳
        params.put("cmd", "searchGoods");
        params.put("data[name]", search.getText().toString());
        OkHttp3ClientManager.getInstance().NetworkRequestMode("http://zmx.123xk.cn/admin/api.make/entry", params, handler, 3, 404);

    }



    public void showPhoto(Goods g) {

        View view;//选择性别的view

        modify_dialogs = new Dialog(mActivity, R.style.ActionSheetDialogStyle);
        //填充对话框的布局
        view = LayoutInflater.from(mActivity).inflate(R.layout.dialog_shopping, null);
        //将布局设置给Dialog
        modify_dialogs.setContentView(view);
        //获取当前Activity所在的窗体
        Window dialogWindow = modify_dialogs.getWindow();

        //设置Dialog从窗体底部弹出
        dialogWindow.setGravity(Gravity.BOTTOM);
        //获得窗体的属性
        WindowManager.LayoutParams lp = dialogWindow.getAttributes();
        //        lp.y = 20;//设置Dialog距离底部的距离

        //// 以下这两句是为了保证按钮可以水平满屏
        lp.width = ViewGroup.LayoutParams.MATCH_PARENT;
        lp.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        // 设置显示位置
        modify_dialogs.onWindowAttributesChanged(lp);
        //       将属性设置给窗体
//        modify_dialogs.setCanceledOnTouchOutside(false);
        modify_dialogs.show();//显示对话框

        TextView name = view.findViewById(R.id.name);
        name.setText("商品名称：" + g.getName());
        TextView desc = view.findViewById(R.id.desc);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            desc.setText("药品描述：" + Html.fromHtml((g.getDescribe()), 10));
        }
        EditText y_number = view.findViewById(R.id.y_number);
        EditText y_sm = view.findViewById(R.id.y_sm);
        EditText e_day = view.findViewById(R.id.e_day);

        TextView regular = view.findViewById(R.id.regular);
        regular.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                final String[] items = {"片/次", "瓶/次", "剂/次"};
                showNotice(regular, items);
            }
        });
        TextView e_rate = view.findViewById(R.id.e_rate);
        e_rate.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                final String[] items = {"每日一次", "每日二次", "每日三次"};
                showNotice(e_rate, items);
            }
        });
        TextView e_usage = view.findViewById(R.id.e_usage);
        e_usage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                final String[] items = {"口服", "外用", "注射"};
                showNotice(e_usage, items);
            }
        });

        Button submit = view.findViewById(R.id.submit);
        submit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                if (y_number.getText().toString().equals("")) {

                    Toast("数量不能为空！");
                    return;

                }

                if (y_sm.getText().toString().equals("")) {

                    Toast("使用说明不能为空！");
                    return;

                }
                if (e_day.getText().toString().equals("")) {

                    Toast("用药时长不能为空！");
                    return;

                }

                GoodsOrder go = new GoodsOrder();
                go.setGoods_id(g.getGoods_id());
                go.setGoods_name(g.getName());
                go.setPrice(g.getPrice());
                go.setNumber(Integer.parseInt(y_number.getText().toString()));
                go.setDay(e_day.getText().toString());
                go.setDescribes(y_sm.getText().toString());
                go.setRate(e_rate.getText().toString());
                go.setUsage(e_usage.getText().toString());
                go.setSpecs("");
                go.setType(0);
                lists.add(go);

                goods.clear();
                goodsItemAdapter.notifyDataSetChanged();
                handler.sendEmptyMessage(0);
                modify_dialogs.dismiss();

            }
        });

    }

}
